﻿using System;
using System.Device.Gpio;
using System.Diagnostics;
using System.Threading;
using nanoFramework.Hardware.Esp32;
using System.Device.Pwm;
using Iot.Device.Ws28xx.Esp32;
using System.Drawing;

///<summary>
//﻿ https://docs.nanoframework.net/devicesdetails/Ws28xx.Esp32/README.html
//using Iot.Device.Ws28xx.Esp32;
//using System.Diagnostics;
//using System.Drawing;

//// Configure the count of pixels
//const int Count = 10;
//// Adjust the pin number
//const int Pin = 15;

//// Use Ws2812 or SK6812 instead if needed
//Ws28xx neo = new Ws2808(Pin, Count);
//Rainbow(neo, Count);

//void Rainbow(Ws28xx neo, int count, int iterations = 1)
//{
//    BitmapImage img = neo.Image;
//    for (var i = 0; i < 255 * iterations; i++)
//    {
//        for (var j = 0; j < count; j++)
//        {
//            img.SetPixel(j, 0, Wheel((i + j) & 255));
//        }

//        neo.Update();
//    }
//}
/// </summary>

namespace NFApp1.Examples
{
    internal class Function_WS28xx
    {

        public void Main()
        {
            Debug.WriteLine("\nFunction WS28xx...\n");

            //var pwmPin = PwmChannel.CreateFromPin(21,4000,0);

            var neo = new Ws2808(21, 10);
            Rainbow(neo, 10);

        
        }

        void Rainbow(Ws28xx neo, int count, int iterations = 1)
        {
            BitmapImage img = neo.Image;
            for (var i = 0; i < 255 * iterations; i++)
            {
                for (var j = 0; j < count; j++)
                {
                    img.SetPixel(j, 0, Color.Red);
                }

                neo.Update();
                Thread.Sleep(100);
            }
        }

      
    }
}
